package com.cater.talents.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.cater.annotation.SystemControllerLog;
import com.cater.common.PageResult;
import com.cater.project.entity.DemandCommunicate;
import com.cater.project.entity.DemandEnterprise;
import com.cater.project.entity.DemandInterview;
import com.cater.project.entity.DemandInvestigation;
import com.cater.project.entity.DemandOfferRecord;
import com.cater.project.service.DemandCommunicateServiceImpl;
import com.cater.project.service.DemandEnterpriseServiceImpl;
import com.cater.project.service.DemandInterviewServiceImpl;
import com.cater.project.service.DemandInvestigationServiceImpl;
import com.cater.project.service.DemandOfferRecordServiceImpl;
import com.cater.query.CommonQuery;
import com.cater.sys.entity.Area;
import com.cater.sys.entity.Company;
import com.cater.sys.entity.Dictionarydata;
import com.cater.sys.service.impl.AreaServiceImpl;
import com.cater.sys.service.impl.CompanyServiceImpl;
import com.cater.sys.service.impl.ContactServiceImpl;
import com.cater.sys.service.impl.DictionarydataServiceImpl;
import com.cater.talents.entity.Contact;
import com.cater.talents.entity.EduExperience;
import com.cater.talents.entity.ExpProject;
import com.cater.talents.entity.RecommendResult;
import com.cater.talents.entity.Resume;
import com.cater.talents.entity.ResumeProject;
import com.cater.talents.entity.TalentsRecommend;
import com.cater.talents.entity.WorkExperience;
import com.cater.talents.service.EduExperienceServiceImpl;
import com.cater.talents.service.ExpProjectServiceImpl;
import com.cater.talents.service.RecommendResultServiceImpl;
import com.cater.talents.service.ResumeProjectServiceImpl;
import com.cater.talents.service.ResumeServiceImpl;
import com.cater.talents.service.TalentsRecommendServiceImpl;
import com.cater.talents.service.WorkExperienceServiceImpl;
import com.cater.talents.utils.FreemarkerUtil;
import com.cater.talents.utils.HtmlUtil;
import com.cater.task.entity.TaskCompletion;
import com.cater.task.entity.TaskManager;
import com.cater.task.service.TaskCompletionServiceImpl;
import com.cater.task.service.TaskManagerServiceImpl;

/**
 * 描述：推荐记录控制层
 * 
 * @author yong
 * @date 2018/08/10
 */
@Controller
@RequestMapping("/talentsRecommend")
public class TalentsRecommendController {

	@Autowired
	private TalentsRecommendServiceImpl service;
	@Autowired
	private ResumeServiceImpl resumeService;// 简历
	@Autowired
	private WorkExperienceServiceImpl experienceService;// 工作经验

	@Autowired
	private CompanyServiceImpl companyService;// 公司

	@Autowired
	private EduExperienceServiceImpl eduExperienceService;// 教育及培训
	@Autowired
	private AreaServiceImpl areaService;// 区域
	@Autowired
	private DemandEnterpriseServiceImpl demandService;// 需求
	@Autowired
	private ExpProjectServiceImpl projectService;// 项目经验
	@Autowired
	private TaskManagerServiceImpl taskManagerService;// 任务
	@Autowired
	private TaskCompletionServiceImpl taskComletionService;// 任务完成情况
	@Autowired
	private ResumeProjectServiceImpl resumeProjectService;// 简历项目关联
	@Autowired
	private ContactServiceImpl contactService;// 企业联系人
	@Autowired
	private DictionarydataServiceImpl dictService;
	@Autowired
	private DemandCommunicateServiceImpl communicateService;
	@Autowired
	private RecommendResultServiceImpl recommendResultService;//
	@Autowired
	private DemandInterviewServiceImpl interviewService;
	@Autowired
	private DemandInvestigationServiceImpl investigationService;
	@Autowired
	private DemandOfferRecordServiceImpl offerRecordService;//

	/**
	 * @推荐记录管理列表视图
	 * @return
	 */
	@RequestMapping("/list")
	public String list() {
		return "talents/talentsRecommend/list";
	}

	/**
	 * @推荐记录管理数据分页
	 * @param query
	 * @param request
	 * @return
	 */
	@RequestMapping("listData")
	@ResponseBody
	@SystemControllerLog(description = "查询推荐记录分页数据")
	public PageResult<TalentsRecommend> listData(CommonQuery query, HttpServletRequest request) {
		PageResult<TalentsRecommend> result = service.findPageResult(query);
		Dictionarydata dictStatus = null;
		for (TalentsRecommend t : result.getRows()) {
			String status = t.getStatus();
			if (StringUtils.isNotEmpty(status)) {
				dictStatus = dictService.getByTypeValue(status, "rec_status");
				if (dictStatus != null) {
					t.setDictStatus(dictStatus.getValueName());
				}
			} else {
				t.setDictStatus("无");
			}
		}
		return result;
	}

	/**
	 * 添加视图
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "addView")
	@RequiresPermissions("talentsRecommend:add")
	public String addView(String talentsId, String demandId, String companyId, String position, Model model) {
		if (StringUtils.isNotEmpty(talentsId)) {
			model.addAttribute("talentsId", talentsId);
		}
		if (StringUtils.isNotEmpty(demandId)) {
			model.addAttribute("demandId", demandId);
		}
		if (StringUtils.isNotEmpty(companyId)) {
			model.addAttribute("companyId", companyId);
			List<Contact> contacts = contactService.getContactList(companyId, null);
			if (contacts.size() > 0) {
				model.addAttribute("contacts", contacts);
			}
		}
		if (StringUtils.isNotEmpty(position)) {
			model.addAttribute("position", position);
		}
		return "talents/talentsRecommend/add";
	}

	/**
	 * 添加操作
	 * 
	 * @param t
	 * @return
	 */
	@RequestMapping(value = "add")
	@RequiresPermissions("talentsRecommend:add")
	@ResponseBody
	@SystemControllerLog(description = "添加推荐记录")
	public JSONObject add(TalentsRecommend t, CommonQuery query, HttpServletRequest request) {
		String path = request.getSession().getServletContext().getRealPath("/");
		JSONObject json = new JSONObject();
		Long filename = Calendar.getInstance().getTimeInMillis();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("path", path);
		try {
			t.setReportDate(new SimpleDateFormat("yyyy年MM月dd日").format(new Date()));
			String id = service.saves(t);
			if (StringUtils.isNotBlank(id)) {
				TalentsRecommend recommend = service.getById(id);
				if (recommend != null) {
					String companyId = recommend.getCompanyId();
					if (StringUtils.isNotEmpty(companyId)) {
						recommend.setCompanyId(companyId);
					} else {
						recommend.setCompanyId(recommend.getCompany().getId());
					}
					map.put("recommend", recommend);
				}
				String talentsId = t.getTalentsId();
				String[] number = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
				if (StringUtils.isNotEmpty(talentsId)) {
					Resume resume = resumeService.getById(talentsId);
					if (resume != null) {
						map.put("resume", resume);
						query.setType("1");
						List<EduExperience> eduExperiences = eduExperienceService.getListByTalentsId(query);
						if (eduExperiences.size() > 0) {
							resume.setEduExperiences(eduExperiences);
							for (EduExperience eduExperience : eduExperiences) {
								String startDate = eduExperience.getStartDate();
								String endDate = eduExperience.getEndDate();
								if (!startDate.equals("至今")) {
									eduExperience.setReportStartDate(getYearMonth(startDate));
								} else {
									eduExperience.setReportStartDate(startDate);
								}
								if (!endDate.equals("至今")) {
									eduExperience.setReportEndDate(getYearMonth(endDate));
								} else {
									eduExperience.setReportEndDate(endDate);
								}
							}
						}
						query.setTalentsId(talentsId);
						List<WorkExperience> workExperiences = experienceService.getListByTalentsId(query);
						if (workExperiences.size() > 0) {
							resume.setWorkExperiences(workExperiences);
							int i = 1;
							for (WorkExperience workExperience : workExperiences) {
								/*
								 * String responsibility = workExperience.getResponsibility();
								 * if(StringUtils.isNotEmpty(responsibility)) {
								 * workExperience.setResponsibility(HtmlUtil.clearWordFormat(responsibility)); }
								 */
								String startDate = workExperience.getStartDate();
								String endDate = workExperience.getEndDate();
								if (!startDate.equals("至今")) {
									workExperience.setReportStartDate(getYearMonth(startDate));
								} else {
									workExperience.setReportStartDate(startDate);
								}
								if (!endDate.equals("至今")) {
									workExperience.setReportEndDate(getYearMonth(endDate));
								} else {
									workExperience.setReportEndDate(endDate);
								}
								workExperience.setNumber(number[i]);
								i++;
							}

						}
						String locationA = resume.getLocation();
						if (StringUtils.isNotEmpty(locationA)) {
							Area locationarea = this.areaService.getById(locationA);
							map.put("location", locationarea.getTreeNames());
						}
						String householdA = resume.getHousehold();
						if (StringUtils.isNotEmpty(householdA)) {
							Area household_area = this.areaService.getById(householdA);
							map.put("household", household_area.getTreeNames());
						}
						String nativesA = resume.getNatives();
						if (StringUtils.isNotEmpty(nativesA)) {
							Area natives_area = this.areaService.getById(nativesA);
							map.put("natives", natives_area.getTreeNames());
						}
					}
				}
				FreemarkerUtil freemarker = new FreemarkerUtil();
				String realname = freemarker.fprint("report_template.ftl", map, filename + ".doc", request);
				if (StringUtils.isNotEmpty(realname)) {
					recommend.setReportFile(realname);
					service.update(recommend);
				}
				json.put("code", 200);
				json.put("message", "success");
			} else {
				json.put("code", 999);
				json.put("message", "fail");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return json;
	}

	/**
	 * 修改视图
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "editView")
	@RequiresPermissions("talentsRecommend:edit")
	public String editView(String id, String position, Model model, CommonQuery query) {
		TalentsRecommend t = service.getById(id);
		model.addAttribute("talentsRecommend", t);
		return "talents/talentsRecommend/update";
	}

	/**
	 * 修改操作
	 * 
	 * @param t
	 * @return
	 */
	@RequestMapping(value = "update")
	@RequiresPermissions("talentsRecommend:edit")
	@ResponseBody
	@SystemControllerLog(description = "修改推荐记录")
	public JSONObject update(TalentsRecommend t, CommonQuery query) {
		JSONObject json = new JSONObject();
		try {
			TalentsRecommend tRecommend = service.getById(t.getId());
			if (tRecommend != null) {
				tRecommend.setResults(t.getResults());
				tRecommend.setArrivalTime(t.getArrivalTime());
				tRecommend.setRemark(t.getRemark());
				service.update(tRecommend);
				json.put("code", 200);
				json.put("message", "修改成功");
			} else {
				json.put("code", 400);
				json.put("message", "修改失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("code", 999);
			json.put("message", "修改失败");
		}
		return json;
	}

	/**
	 * 删除操作
	 * 
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("talentsRecommend:delete")
	@SystemControllerLog(description = "删除推荐记录")
	public JSONObject delete(String id) {
		JSONObject json = new JSONObject();
		try {
			service.delete(id);
			json.put("code", 200);
			json.put("message", "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			json.put("code", 999);
			json.put("message", "删除失败");
		}
		return json;
	}

	@ResponseBody
	@RequestMapping("/report")
	public JSONObject Report(String talentsId, TalentsRecommend t, HttpServletRequest request, CommonQuery query) {
		JSONObject json = new JSONObject();
		Long filename = Calendar.getInstance().getTimeInMillis();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
		String dateString = formatter.format(new Date());
		String companyId = null;
		try {
			Resume resume = resumeService.getById(talentsId);
			String cellphone = resume.getCellphone();
			String lifephone = resume.getLifephone();
			String temp = "";
			TaskManager taskManager = null;
			Company company = null;
			if (StringUtils.isNotEmpty(cellphone)) {
				temp += cellphone;
			} else if (StringUtils.isNotEmpty(lifephone)) {
				temp += lifephone;
			} else {
				temp = "暂无";
			}
			String[] number = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
			resume.setPhoneview(temp);
			query.setTalentsId(talentsId);
			List<WorkExperience> workExperiences = experienceService.getListByTalentsId(query);
			List<ExpProject> eProjects = null;
			if (workExperiences.size() > 0) {
				resume.setWorkExperiences(workExperiences);
				int i = 1;
				for (WorkExperience workExperience : workExperiences) {
					String responsibility = workExperience.getResponsibility();
					if (StringUtils.isNotEmpty(responsibility)) {
						workExperience.setResponsibility(HtmlUtil.clearWordFormat(responsibility));
					}
					String startDate = workExperience.getStartDate();
					String endDate = workExperience.getEndDate();
					if (!startDate.equals("至今")) {
						workExperience.setReportStartDate(getYearMonth(startDate));
					} else {
						workExperience.setReportStartDate(startDate);
					}
					if (!endDate.equals("至今")) {
						workExperience.setReportEndDate(getYearMonth(endDate));
					} else {
						workExperience.setReportEndDate(endDate);
					}
					workExperience.setNumber(number[i]);
					eProjects = new ArrayList<ExpProject>();
					String workId = workExperience.getId();
					if (StringUtils.isNotEmpty(workId)) {
						query.setWorkExpId(workId);
						eProjects = projectService.getByWorkId(query);
						workExperience.seteProject(eProjects);
					}
					i++;
				}

			}
			query.setType("1");
			List<EduExperience> eduExperiences = eduExperienceService.getListByTalentsId(query);
			if (workExperiences.size() > 0) {
				resume.setEduExperiences(eduExperiences);
				for (EduExperience eduExperience : eduExperiences) {
					String startDate = eduExperience.getStartDate();
					String endDate = eduExperience.getEndDate();
					if (!startDate.equals("至今")) {
						eduExperience.setReportStartDate(getYearMonth(startDate));
					} else {
						eduExperience.setReportStartDate(startDate);
					}
					if (!endDate.equals("至今")) {
						eduExperience.setReportEndDate(getYearMonth(endDate));
					} else {
						eduExperience.setReportEndDate(endDate);
					}
				}
			}

			query.setType("2");
			List<EduExperience> trainExperiences = eduExperienceService.getListByTalentsId(query);
			if (workExperiences.size() > 0) {
				resume.setTrainExperiences(trainExperiences);
			}
			DemandEnterprise demand = demandService.getById(t.getDemandId());
			if (demand != null) {
				companyId = demand.getCompany().getId();
				company = companyService.getById(companyId);
				if (company != null) {
					demand.setCompany(company);
				}
				taskManager = taskManagerService.getByDemandId(demand.getId());
			}
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("doc", resume);
			map.put("demand", demand);
			map.put("posts", t.getPosts());
			map.put("reason", t.getReason());
			map.put("datenow", dateString);
			map.put("ArrivalTime", t.getArrivalTime());
			String locationA = resume.getLocation();
			if (StringUtils.isNotEmpty(locationA)) {
				Area locationarea = this.areaService.getById(locationA);
				map.put("location", locationarea.getTreeNames());
			}
			String householdA = resume.getHousehold();
			if (StringUtils.isNotEmpty(householdA)) {
				Area household_area = this.areaService.getById(householdA);
				map.put("household", household_area.getTreeNames());
			}
			String nativesA = resume.getNatives();
			if (StringUtils.isNotEmpty(nativesA)) {
				Area natives_area = this.areaService.getById(nativesA);
				map.put("natives", natives_area.getTreeNames());
			}
			FreemarkerUtil freemarker = new FreemarkerUtil();
			String realname = freemarker.fprint("recommend_report.ftl", map, filename + ".doc", request);
			t.setCompanyId(companyId);
			t.setReportFile(realname);
			t.setTalentsId(talentsId);
			String id = service.saves(t);
			if (StringUtils.isNotEmpty(id)) {
				json.put("code", 200);
				json.put("doc", realname);
				json.put("message", "推荐报告生成成功");
				TaskCompletion taskCompletion = new TaskCompletion();
				if (taskManager != null) {
					taskCompletion.setTaskId(taskManager.getId());
					taskCompletion.setType("1");
					taskCompletion.setCompletes("完成对" + company.getName() + ",岗位：" + t.getPosts() + "的推荐。");
					taskCompletion.setAttachment(realname);
					taskComletionService.saves(taskCompletion);
				}
				ResumeProject resumeProject = new ResumeProject();
				ResumeProject oldresumeProject = new ResumeProject();
				resumeProject.setResumeId(talentsId);
				resumeProject.setProjectId(t.getDemandId());
				resumeProject.setStatus("6");
				oldresumeProject = resumeProjectService.getByPidAndRid(talentsId, t.getDemandId());
				if (oldresumeProject != null) {
					resumeProjectService.update(resumeProject);
				} else {
					resumeProjectService.saves(resumeProject);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("code", 999);
			json.put("message", "推荐报告生成失败");
		}
		return json;

	}

	private String getYearMonth(String date) {
		String temp = date.replaceAll("-", "年") + "月";
		return temp;
	}

	/**
	 * 修改推荐状态视图
	 * 
	 * @param id
	 * @param model
	 * @param query
	 * @return
	 */
	@RequestMapping(value = "statusView")
	public String statusView(String id, Model model, CommonQuery query) {
		TalentsRecommend t = service.getById(id);
		model.addAttribute("talentsRecommend", t);
		return "talents/talentsRecommend/update_status";
	}

	/**
	 * 修改推荐状态
	 * 
	 * @param id
	 * @param status
	 * @param query
	 * @return
	 */
	@RequestMapping(value = "updateStatus")
	@ResponseBody
	@SystemControllerLog(description = "修改推荐状态")
	public JSONObject updateStatus(String id, String status, Integer ispast) {
		JSONObject json = new JSONObject();
		try {
			if (StringUtils.isNotEmpty(id)) {
				TalentsRecommend t = service.getById(id);
				if (t != null) {
					if (StringUtils.isNotBlank(status)) {
						t.setStatus(status);
					}
					if (ispast > 0) {
						t.setIsPast(ispast);
					}
					service.update(t);
					json.put("code", 200);
					json.put("message", "状态修改成功");
				}
			} else {
				json.put("code", 400);
				json.put("message", "数据不存在");
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("code", 500);
			json.put("message", "状态修改异常");
		}
		return json;
	}

	/**
	 * 
	 * @Description:沟通时间轴
	 * @param id
	 * @return String
	 * @time:2019年4月2日 下午9:25:10
	 */
	@RequestMapping("/timeLine")
	public String timeLine(String id, Model model, CommonQuery query) {
		List<Map<String, String>> list = new ArrayList<Map<String,String>>();
		Map<String, String> map = null;
		try {
			if (StringUtils.isNotEmpty(id)) {
				TalentsRecommend recommend = service.getById(id);
				if (recommend != null) {
					String status = String.valueOf(recommend.getIsPast());
					if (StringUtils.isNotEmpty(status)) {
						map = new HashMap<String, String>();
						String htm = "";
							map.put("title", "推荐");
							map.put("content",
									"推荐时间：" + recommend.getReportDate() + "<br>推荐理由：" + recommend.getReason());
							htm = "<a href=\"\" onclick=\"openpage(1,&quot;" + id
									+ "&quot;)\" style=\"color:#FFF;font-weight:bold\">查看详情</a>";
							map.put("url", htm);
							list.add(map);
							List<DemandCommunicate> communicates = communicateService.getByRecommandId(id);
							if (communicates.size() > 0) {
								for (DemandCommunicate demandCommunicate : communicates) {
									String classid = demandCommunicate.getClassid();
									String communicateId = demandCommunicate.getId();
									if (StringUtils.isNotEmpty(classid)) {
										map = new HashMap<String, String>();
										if (classid.equals("2")) {
											map.put("title", "初试");
											map.put("content", "沟通时间：" + demandCommunicate.getCreateDate());
											htm = "<a href=\"\" onclick=\"openpage(2,&quot;" + communicateId
													+ "&quot;)\" style=\"color:#FFF;font-weight:bold\">查看详情</a>";
											map.put("url", htm);
											list.add(map);
										}
										if (classid.equals("3")) {
											map.put("title", "复试");
											map.put("content", "沟通时间：" + demandCommunicate.getCreateDate());
											htm = "<a href=\"\" onclick=\"openpage(3,&quot;" + communicateId
													+ "&quot;)\" style=\"color:#FFF;font-weight:bold\">查看详情</a>";
											map.put("url", htm);
											list.add(map);
										}
										if (classid.equals("4")) {
											map.put("title", "终试");
											map.put("content", "沟通时间：" + demandCommunicate.getCreateDate());
											htm = "<a href=\"\" onclick=\"openpage(4,&quot;" + communicateId
													+ "&quot;)\" style=\"color:#FFF;font-weight:bold\">查看详情</a>";
											map.put("url", htm);
											list.add(map);
										}
										if (classid.equals("5")) {
											map.put("title", "背调");
											map.put("content", "背调时间：" + demandCommunicate.getCreateDate());
											htm = "<a href=\"\" onclick=\"openpage(5,&quot;" + communicateId
													+ "&quot;)\" style=\"color:#FFF;font-weight:bold\">查看详情</a>";
											map.put("url", htm);
											list.add(map);
										}
										if (classid.equals("6")) {
											map.put("title", "已发offer");
											map.put("content", "发放时间：" + demandCommunicate.getCreateDate());
											htm = "<a href=\"\" onclick=\"openpage(6,&quot;" + communicateId
													+ "&quot;)\" style=\"color:#FFF;font-weight:bold\">查看详情</a>";
											map.put("url", htm);
											list.add(map);
										}
										if (classid.equals("7")) {
											map.put("title", "未过保障期");
											map.put("content", "时间：" + demandCommunicate.getCreateDate());
											htm = "<a href=\"\" onclick=\"openpage(7,&quot;" + communicateId
													+ "&quot;)\" style=\"color:#FFF;font-weight:bold\">查看详情</a>";
											map.put("url", htm);
											list.add(map);
										}
										if (classid.equals("8")) {
											map.put("title", "已过保障期");
											map.put("content", "时间：" + demandCommunicate.getCreateDate());
											htm = "<a href=\"\" onclick=\"openpage(8,&quot;" + communicateId
													+ "&quot;)\" style=\"color:#FFF;font-weight:bold\">查看详情</a>";
											map.put("url", htm);
											list.add(map);
										}
										if (classid.equals("9")) {
											map.put("title", "完成");
											map.put("content", "完成时间：" + demandCommunicate.getCreateDate());
											htm = "<a href=\"\" onclick=\"openpass(&quot;" + communicateId
													+ "&quot;)\" style=\"color:#FFF;font-weight:bold\">查看详情</a>";
											map.put("url", htm);
											list.add(map);
										}
									}
								}
							}
							if (status.equals("2")) {
							query.setRecommendId(id);
							List<RecommendResult> recommendResults = recommendResultService.getListBy(query);
							String result = "暂无";
							if (recommendResults.size() > 0) {
								for (RecommendResult recommendResult : recommendResults) {
									result = recommendResult.getResults();
								}
							}
							map.put("title", "推荐");
							map.put("content", "推荐结果：" + result);
							list.add(map);
						}

					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		model.addAttribute("list", list);
		return "talents/talentsRecommend/timeline";
	}

	/**
	 * 
	 * @Description:查看时间轴详情
	 * @param query
	 * @param model
	 * @return String
	 * @time:2019年4月6日 下午12:36:47
	 */
	@RequestMapping("/timeLineView")
	public String timeLineView(CommonQuery query, Model model) {
		String classid = query.getClassid();
		if (StringUtils.isNotEmpty(classid)) {
			model.addAttribute("classid", classid);
		}
		String id = query.getId();
		if (StringUtils.isNotEmpty(id)) {
			model.addAttribute("id", id);
		}
		return "talents/talentsRecommend/timeline_detail";
	}

	/**
	 * 
	 * @Description:时间轴详情json
	 * @param query
	 * @return JSONObject
	 * @time:2019年4月6日 下午6:08:26
	 */
	@ResponseBody
	@RequestMapping("/timeLineJson")
	public JSONObject timeLineJson(CommonQuery query) {
		JSONObject json = new JSONObject();
		String id = query.getId();
		String classid = query.getClassid();
		try {
			if (classid.equals("1")) {
				if (StringUtils.isNotEmpty(id)) {
					TalentsRecommend recommend = service.getById(id);
					if (recommend != null) {
						query.setRecommendId(recommend.getId());
						List<RecommendResult> results = recommendResultService.getListBy(query);
						if (results.size() > 0) {
							json.put("results", results);
						}
						json.put("title", "加入项目");
						json.put("recommend", recommend);
					}
				}
			} else {
				if (StringUtils.isNotEmpty(id)) {
					DemandCommunicate communicate = communicateService.getById(id);
					if (communicate != null) {
						Dictionarydata dict = dictService.getByTypeValue(classid, "resume_status");
						query.setCommunicateId(communicate.getId());
						json.put("title", dict.getValueName());
						json.put("communicate", communicate);
						if (classid.equals("2") || classid.equals("3") || classid.equals("4")) {
							List<DemandInterview> list = interviewService.getListBy(query);
							if (list.size() > 0) {
								json.put("list", list);
							}
						}
						if (classid.equals("5")) {
							List<DemandInvestigation> investigations = investigationService.getListBy(query);
							if (investigations.size() > 0) {
								json.put("investigations", investigations);
							}
						}
						if (classid.equals("6")) {
							List<DemandOfferRecord> offerRecords = offerRecordService.getListBy(query);
							if (offerRecords.size() > 0) {
								json.put("offerRecords", offerRecords);

							}
						}
						if (classid.equals("7")) {
							List<DemandOfferRecord> offerRecords = offerRecordService.getListBy(query);
							if (offerRecords.size() > 0) {
								json.put("offerRecords", offerRecords);

							}
						}
					}
				}
			}
			json.put("code", 200);
			json.put("message", "数据获取成功");
		} catch (Exception e) {
			e.printStackTrace();
			json.put("code", 500);
			json.put("message", "数据获取异常");
		}
		return json;
	}

	@ResponseBody
	@RequestMapping("/isExists")
	public JSONObject isExists(CommonQuery query) {
		JSONObject json = new JSONObject();
		try {
			String talentsId = query.getTalentsId();
			String demandId = query.getDemandId();
			if (StringUtils.isNotEmpty(talentsId) && StringUtils.isNotEmpty(demandId)) {
				List<TalentsRecommend> recommends = service.getListBy(query);
				if (recommends.size() > 0) {
					TalentsRecommend recommend = recommends.get(0);
					json.put("code", 200);
					json.put("message",
							recommend.getCreateUser().getTruename() + "于" + recommend.getCreateDate().substring(0, 10)
									+ "将" + recommend.getResume().getTrueName() + "推荐过该岗位");
				} 
			} else {
				json.put("code", 400);
				json.put("message", "查询条件不符合");
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("code", 500);
			json.put("message", "查询数据异常");
		}
		return json;
	}
}